<html lang="zh-CN"><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<title>在线预订</title>
<link rel="stylesheet" type="text/css" href="wx_assets/css/store_reserve_sel_num.css?v=2013-11-27">
<script type='text/javascript' src="wx_assets/js/wei_webapp_v2_common.js"></script>
<script type='text/javascript' src='wx_assets/js/jquery-1.7.1.min.js'></script>
<script src="http://res.wx.qq.com/mmbizwap/en_US/htmledition/js/wxm-core1530d0.js"></script>
<script type='text/javascript' src="wx_assets/js/alert.js"></script>
<style>abbr,article,aside,audio,canvas,datalist,details,dialog,eventsource,fieldset,figure,figcaption,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,small,time,video,legend{display:block;}</style>

<style>

</style>
</head>
<body id="page_count" style="height: 356px; ">

<div class="center main">
	<section>
		<ol style="width: 530px; "></ol>
	</section>
</div>

<div class="notice">
	<b>请选择您的用餐人数</b>
	<!--<p>通过左右滑动来选择您的用餐人数，选择<br/>完成后点击点菜按钮即可</p>-->
</div>
<div class="notice">
	<ul class="round">
		<li class="nob" >
			<table width="100%" border="0" cellspacing="0" cellpadding="0"
				class="kuang">
				<tr>
					<th>预订日期</th>
					<td>
						<select name="dateline" id="dateline" class="dropdown-select" style="width: 130px; ">
							<volist name="dates" id="date">
								<option value="{$date.dateTime}">{$date.dateTime}</option>
							</volist>
						</select>
					</td>
				</tr>
			</table>
		</li>
		<li class="nob">
			<table width="100%" border="0" cellspacing="0" cellpadding="0"
				class="kuang">
				<tr>
					<th>预订时间</th>
					<td>
						<select name="timeline" id="timeline" class="dropdown-select" style="width: 130px; ">
							<volist name="times" id="time">
								<option value="{$time.timeId}">{$time.timeDisplay}</option>
							</volist>
						</select>
					</td>
				</tr>
			</table>
		</li>
		</ul>
</div>

<div class="notice" style="clear:both;height:1px;">
	<b></b>
</div>

<div class="center">
<a class="order" href='javascript:void(0)' onclick="doSelected()" id="order" style="margin-top:50px;"><span>开始预订</span></a>
</div>

<script>
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
	WeixinJSBridge.call('showOptionMenu');
	});

var hrefParamsArray = GetSessionIdFromHref(window.location.search);

function GetSessionIdFromHref(search){
　　	var args = search.substring(1); 
　　	var retval = new Array(); 
	args = args.split("&"); 
		for(var i = 0; i < args.length; i ++){ 
			str = args[i]; 
			var arg = str.split("="); 
			if(arg.length <= 1) continue; 
			if(arg[0] == 'params') {
				var params = decodeURIComponent(arg[1]);
				var obj = eval('(' + params + ')');
				retval["id"] = obj.id;
			}else if(arg[0] == 'customerId') {
				retval["customerId"] = arg[1]; 
			}else if(arg[0] == 'userName'){
				retval["userName"] = arg[1]; 
			}
		} 
		return retval; 
}

</script>
<script>
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
	WeixinJSBridge.call('showOptionMenu');
	});
	
		function report(link, fakeid, action_type){
		    var parse_link = parseUrl(link);
		    if(parse_link == null)
		    {
		      return ;
		    }
		    var query_obj = parseParams( parse_link['query_str'] );
		    query_obj['action_type'] = action_type;
		    query_obj['uin'] = fakeid;
		    var report_url = '/mp/appmsg/show?' + jQuery.param( query_obj );
		    jQuery.ajax({
		      url: report_url,
		      type: 'POST',
		      timeout: 2000
		    })
		 };
		 
		function share_scene(link, scene_type) {
			// Android无法会截取encode的参数，所以改用直接添加参数的方式
			var share_url = link + '&scene=' + scene_type;
			return share_url;
		};

		(function() {
			var desString ='帮我预订'+ "\n点击查看预订详情";
			var titleString = "在线预订";
			
		//	var search = resetHerf(window.location.search);
			var search = window.location.search;

			var onBridgeReady = function() {
			var link = window.location.protocol + "//"
						+ window.location.host + window.location.pathname + search;
		
				link = link.replace("{", "%7B");
				link = link.replace("}", "%7D");
				var appId = '', title = htmlDecode(titleString), desc = htmlDecode(desString),
				imgUrl = encodeURI('http://www.happyidea.com.cn/wx_assets/images/store/pagecount_main_bk.jpg'), fakeid = "Mjc2OTgzMTM1", desc = desc || link;

				// 发送给好友; 
				WeixinJSBridge.on('menu:share:appmessage', function(argv) {

					WeixinJSBridge.invoke('sendAppMessage', {
						"appid" : appId,
						"img_url" : imgUrl,
						"img_width" : "640",
						"img_height" : "640",
						"link" : share_scene(link, 1),
						"desc" : desc,
						"title" : title
					}, function(res) {
						report(link, fakeid, 1);
					});
				});
				// 分享到朋友圈;
				WeixinJSBridge.on('menu:share:timeline', function(argv) {
					report(link, fakeid, 2);
					WeixinJSBridge.invoke('shareTimeline', {
						"img_url" : imgUrl,
						"img_width" : "640",
						"img_height" : "640",
						"link" : share_scene(link, 2),
						"desc" : desc,
						"title" : title
					}, function(res) {
					});

				});

				// 分享到微博;
				var weiboContent = '';
				WeixinJSBridge.on('menu:share:weibo', function(argv) {

					WeixinJSBridge.invoke('shareWeibo', {
						"content" : title + share_scene(link, 3),
						"url" : share_scene(link, 3)
					}, function(res) {
						report(link, fakeid, 3);
					});
				});
				// 隐藏右上角的选项菜单入口;
				//WeixinJSBridge.call('hideOptionMenu');
			};
			if (document.addEventListener) {
				document.addEventListener('WeixinJSBridgeReady', onBridgeReady,
						false);
			} else if (document.attachEvent) {
				document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
				document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
			}
		})();
	</script>

<script>

var breakfastTime = "{$breakfastTime}";
var lunchTime = "{$lunchTime}";
var dinnerTime = "{$dinnerTime}";

var cardid = "3414907165";

var nums = new Array() ;

    nums.push(2);
    nums.push(4);
    nums.push(6);
    nums.push(8);
    nums.push(10);
    nums.push(12);
    nums.push(16);

var _selectedCount = 0; //选择好的人数会同步到这个变量里

function SliderChooser(config){ var container = _q(config.containerContext), inner = _q(config.innerContext, container), nums = config.nums, itemW = config.itemWidth, curr = 1, w = container.clientWidth, drag_start = {time: 0, left: 0, top: 0, x: 0, y: 0, lx: 0, ly: 0}, drag_end = {left: 0}, directionLocked = null, time = function(){ return (new Date).getTime(); }, getP = function(e){ var t = e.touches[0], c = e.currentTarget.parentNode, r = c.parentNode.getClientRects()[0]; return { x: t.pageX-r.left, y: t.pageY-r.top, px: t.pageX, py: t.pageY, cx: t.clientX, cy: t.clientY, sx: t.screenX, sy: t.screenY }; }, getLeft = function(dom){ return parseFloat( /\((\-?[\.\d]+)px/.exec( dom.style[_vendor + 'Transform'] )[1] ); }, setCurr = function(idx) { curr = idx; _forEach(_qAll(config.itemContext, inner), function(li, liIdx){ _removeClass(li, config.currentStyleClass); if (idx == liIdx){ _addClass(li, config.currentStyleClass); } }); }, doTransition = function(value, tweenMode) { var d = tweenMode? /*as idx*/-value*itemW : value, s = tweenMode ? 6.18 * 4 * .01 : 0; inner.style[_vendor + 'TransitionDuration'] = s + 's'; inner.style[_vendor + 'Transform'] = _trnOpen + d + 'px,0' + _trnClose; }, e_ts = function(e) /*touchstart*/ { if (!_touchSupport) e.preventDefault(); directionLocked = null; var p1 = getP(e), p2 = { x: drag_end.left*1, y: inner.getClientRects()[0].top }; drag_start = { time: time(), left: p2.x, top: p2.y, x: parseInt(p2.x - p1.x), y: parseInt(p2.y - p1.y), lx: e.touches[0].clientX, ly: e.touches[0].clientY, point: p1 }; e.currentTarget.addEventListener("touchmove", e_tm); e.currentTarget.addEventListener("touchend", e_te); e.currentTarget.addEventListener("touchcancel", e_te); }, e_tm = function(e) /*touchmove*/ { if (!_touchSupport) e.preventDefault(); var p = getP(e), c = e.currentTarget.parentNode, v = drag_start.x + p.x; /*横纵拖动互不干扰*/ var absDistX, absDistY, deltaX = e.touches[0].pageX - drag_start.point.px, deltaY = e.touches[0].pageY - drag_start.point.py; if (directionLocked === "y") { return } else { if (directionLocked === "x") { e.preventDefault() } else { absDistX = Math.abs(deltaX); absDistY = Math.abs(deltaY); if (absDistX < 4) { return } if (absDistY > absDistX * 0.58) { directionLocked = "y"; return } else { e.preventDefault(); directionLocked = "x"; } } } doTransition( v ); if (MData(c, 'touching') === undefined || MData(c, 'touching')*1 != 1) MData(c, 'touching', 1); }, e_te = function(e) /*touchend*/ { if (!_touchSupport)	e.preventDefault(); e.currentTarget.removeEventListener("touchmove", e_tm); e.currentTarget.removeEventListener("touchend", e_te); e.currentTarget.removeEventListener("touchcancel", e_te); var c = e.currentTarget.parentNode; MData(c, 'touching', 0); try{ drag_end.left = getLeft(c); }catch(ex){} var idx = curr, p2 = { x: drag_end.left, y: c.getClientRects()[0].top }, tTime = time() - drag_start.time, tDis = p2.x - drag_start.left, shortDis = Math.abs(tDis)<5, longTime = tTime > 300; if (!longTime && !shortDis){ /*快速拖动*/ if (tDis < 0) /*left*/ idx++; else /*right*/ idx--; }else{ /*一般拖动*/ if ( Math.abs(tDis) > .5*itemW ){ var d1 = Math.abs(Math.round(tDis/itemW)); if( tDis < 0 ) idx += d1; else idx -= d1; } } if (idx<1) idx = 1; if (idx>=nums.length-2) idx = nums.length-2; doTransition(idx-1, true); drag_end.left = getLeft(c); setCurr(idx); if ('callback' in config && !!config.callback){ config.callback.call(null, curr-1); } }; nums.unshift(-1); nums.push(-1); _forEach(nums, function(n,idx,arr){ inner.insertAdjacentHTML('beforeEnd', '<'+config.itemContext+'>'+n+'</'+config.itemContext+'>'); var li = _q(config.itemContext+':last-of-type', inner); if (idx==0 || idx == arr.length-1){ _addClass(li, 'sider'); return; } li.addEventListener("touchstart", e_ts); li = null; }); inner.style.width = itemW * nums.length + 'px'; setCurr(1); };
function scCallback(currIdx){
	_forEach(_qAll('section li'), function(li){
		_removeClass(li, 'left');
		_removeClass(li, 'right');
	});
	var l = _q('section li:nth-of-type('+(currIdx+1)+')'),
		r = _q('section li:nth-of-type('+(currIdx+3)+')');
	_addClass(l, 'left');
	_addClass(r, 'right');
	l = null;
	r = null;
	_selectedCount = parseInt(_q('section li:nth-of-type('+(currIdx+2)+')').innerHTML);
}
_onPageLoaded(function(){
    _q('body').scrollTop = -1; 
    window.scrollTo(0,-1); 
    _q('body').style.height = window.innerHeight + 'px'; 
    var obtn = _q('.order'); 
    obtn.style.marginTop = '35px'; //(window.innerHeight - 280 - 75) + 'px';
    
	SliderChooser({
		nums: nums,
		containerContext: 'section',
		innerContext: 'ol',
		itemContext: 'li',
		itemWidth: 106,
		currentStyleClass: 'curr',
		callback: scCallback
	});
	scCallback(0);
});
function doSelected() {
	
	if($("#dateline").val()==''){alert('请选择预订日期');return;}
	if($("#timeline").val()==''){alert('请选择用餐时间');return;}
	var curDate =  new Date();//现在
	
	var curDateStr = curDate.getFullYear()+"-"+(curDate.getMonth()+1)+"-"+curDate.getDate();
	var todayDate = new Date(curDateStr);
	
	
	var dateline = $('#dateline').val();
	var reserveType = $('#timeline').val();
	
	var dateLineDate= new Date(dateline);
	
	var dateLineStr = dateLineDate.getFullYear()+"-"+(dateLineDate.getMonth()+1)+"-"+dateLineDate.getDate();
	dateLineDate = new Date(dateLineStr);

	if($("#dateline").val()==''){alert('请选择预订日期');return;}
	if($("#timeline").val()==''){alert('请选择用餐时间');return;}
	var curDate =  new Date();//现在
	var curDateStr = (curDate.getMonth()+1)+"-"+curDate.getDate()+"-"+curDate.getFullYear();
	
	var todayDate = new Date(curDate.getFullYear(),curDate.getMonth(),curDate.getDate(),0,0,0);
	
	var dateline = $('#dateline').val();
	var reserveType = $('#timeline').val();
	dateline = dateline+" 00:00:00";
	var dateLineDateValue = Date.parse(dateline.replace(/-/g,   "/"));//毫秒值
	
	if(todayDate.valueOf() == dateLineDateValue){
		
		//var breakfast = new Date(curDateStr + " "+breakfastTime);
		var lunchStr = curDateStr + " "+lunchTime;
		var dinnerStr = curDateStr + " "+dinnerTime;
		var lunch =  Date.parse(lunchStr.replace(/-/g,   "/"));
		var dinner = Date.parse(dinnerStr.replace(/-/g,   "/"));
		
		if(dinnerTime != "" && lunchTime != ""){
			if(curDate.valueOf() >= dinner){
				alert('今日订餐时间结束，请重新选择预订日期');
				return ;
			}else if(curDate.valueOf()>=lunch && reserveType=='lunch'){
				alert('当日午餐预订时间已结束，只能预订晚餐，请重新选择');
				return ;
			}
		}
	
	 }
	
	
	//var reserveTime = dateline+" "+timeline;
	var reserveDate = dateline;
	var baseUrl =  '{$Think.config.SERVER_HOST}';
	var urlString = baseUrl + 'call.html?customerId='+ hrefParamsArray["customerId"]+'&userName='+hrefParamsArray["userName"]
		+ "&module=store&method=reserve&params={\"id\":" + hrefParamsArray["id"] + ",\"reserveDate\":\""+reserveDate+ "\",\"reserveType\":\""+reserveType+"\",\"personCount\":" + _selectedCount+ "}";
	
	location.href= urlString;
	
}

</script>

</body></html>